<?php

declare(strict_types=1);

/**
 * @Author:     Frank
 * @contact     frank_hhm@163.com
 * @Date:       2023-02-16 18:36:25
 * @Last Modified time: 2023-02-17 17:06:05
 */
namespace app\common\model\store;

use frank\base\BaseModel;
use frank\traits\ModelTrait;
use app\common\model\store\GoodsModel;
use app\common\enum\EnumFactory;

/**
 * 商品评价
 * Class GoodsCommentModel
 * @package app\common\model\store
 */
class GoodsCommentModel extends BaseModel
{
	use ModelTrait;
    /**
     * 数据表主键
     */
    protected $pk = 'id';

    /**
     * 模型名称
     */
    protected $name = 'store_goods_comment';

    /**
     * 订单商品列表
     * @return \think\model\relation\hasOne
     */
    public function goods()
    {
        return $this->hasOne("app\\common\\model\\store\\OrderGoodsModel",'id','order_goods_id');
    }

    /**
     * 一对一关联用户表 (简单信息)
     * @return \think\model\relation\HasOne
     */
    public function user()
    {
        return $this->hasOne("app\\common\\model\\user\\UserModel", 'id', 'user_id')->field(['id','nickName', 'avatar'])->bind([
            'user_nickName' => 'nickName',
            'user_avatar' => 'avatar'
        ]);
    }

    /**
     * 评分修改器
     */
    public function getRateAttr($value)
    {
        return EnumFactory::instance('store.goods.comment')->getItem($value);
    }
}